package com.wqtz.chechai.model;

import com.okhttplib.HttpInfo;
import com.okhttplib.OkHttpUtil;
import com.okhttplib.annotation.CacheLevel;
import com.okhttplib.callback.CallbackOk;
import com.wqtz.chechai.api.Constans;
import com.wqtz.chechai.bean.CarInfo;
import com.wqtz.chechai.utils.JsonUtils;

import java.io.IOException;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2016/12/22 15:15
 */

public class CarInfoModel {
	public static CarInfo getCarInfo(String VIN) {
		String url = String.format(Constans.VIN_TO_CAR_INFO, VIN, Constans.VIN_TO_CAR_KEY);
		final CarInfo[] carInfo = {new CarInfo()};
		//加载数字
		OkHttpUtil.Builder().setCacheLevel(CacheLevel.FIRST_LEVEL).setConnectTimeout(25).build().doGetAsync(
				HttpInfo.Builder().setUrl(url).build(), new CallbackOk() {
					@Override
					public void onResponse(HttpInfo info) throws IOException {
						if (info.isSuccessful()) {
							String result = info.getRetDetail();
							if (result != null) {
								carInfo[0] = JsonUtils.getCarInfoBean(result);
							} else {
								carInfo[0]=null;
							}

						} else {
							carInfo[0] = null;
						}

					}
				});
		return carInfo[0];
	}
}
